package com.itheima.controller;

import com.itheima.common.entity.Result;
import com.itheima.pojo.OrderDTO;
import com.itheima.pojo.OrderVo;
import com.itheima.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/order")
@Api(tags = "预约相关")
public class OrderController {

    @Autowired
    private OrderService orderService;


    /**
     * 用户预约接口
     * @param orderDTO
     * @return
     */
    @PostMapping("/submitOrder")
    @ApiOperation("用户预约接口")
    public Result<Integer> insert (@RequestBody OrderDTO orderDTO) {
        orderService.add(orderDTO);
        return Result.success(orderDTO.getId());
    }

    /**
     * 根据id查询预约信息
     * @param id
     * @return
     */
    @GetMapping("/findById")
    @ApiOperation("根据id查询预约信息")
    public Result<OrderVo> getById (@RequestParam Integer id) {
        OrderVo orderVo = orderService.getById(id);
        return Result.success(orderVo);
    }
}
